<%@page
import="web.Topic"
import="java.util.*"
language="java"
contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<body>
  

<%
int nowpage=1;
int pagesize=0;
String g_size=Topic.getSize();
String g_nowpage=request.getParameter("p");
if(g_nowpage!=null){
	nowpage=Integer.parseInt(g_nowpage);
}
if(g_size!=null){
	int size=Integer.parseInt(g_size);
	if(size%10==0){
		pagesize=size/10;
	}else{
		pagesize=size/10+1;
	}
}
HttpSession s=request.getSession();
String cont=request.getParameter("cont");
int tid=Integer.parseInt(request.getParameter("tid"));
if(cont!=null&&!cont.equals("")){
	int uid=(int)s.getAttribute("uid");
	Topic.reply(uid, tid, cont);
}
List<Map> posts=Topic.getPosts(tid,nowpage);
%>

<table>
<%for(Map post:posts){ %>
	<tr>
	<td><%=post.get("uname") %></td>
	<td><%=post.get("cont") %></td>
	<td><%=post.get("create_time") %></td>
	</tr>
<%} %>
</table>

<form action="" method="get">
<%if(s.getAttribute("uname")!=null){ %>
	<p><textarea name="cont"></textarea></p>
	<p><input type="submit"></p>
	<p><input type="hidden" name="tid" value="<%=tid%>"></p>
<%} %>
<a href="index.jsp">返回首页</a>
</form>
<p>
第<%=nowpage %>页
<%for(int i=1;i<=pagesize;i++){ %>
	<a href="post.jsp?tid=<%=tid %>&p=<%=i %>"><%=i %></a>
<%} %>
共<%=pagesize %>页
</p>